﻿using System;
using System.Collections.Generic;
using System.Linq;
using Helpers;
using TaleWorlds.CampaignSystem.Actions;
using TaleWorlds.CampaignSystem.CharacterDevelopment;
using TaleWorlds.CampaignSystem.Conversation;
using TaleWorlds.CampaignSystem.Encounters;
using TaleWorlds.CampaignSystem.GameMenus;
using TaleWorlds.CampaignSystem.MapEvents;
using TaleWorlds.CampaignSystem.Party;
using TaleWorlds.CampaignSystem.Party.PartyComponents;
using TaleWorlds.CampaignSystem.Roster;
using TaleWorlds.CampaignSystem.Settlements;
using TaleWorlds.Core;
using TaleWorlds.Library;
using TaleWorlds.Localization;
using TaleWorlds.ObjectSystem;
using TaleWorlds.SaveSystem;

namespace TaleWorlds.CampaignSystem.Issues
{
	// Token: 0x0200030D RID: 781
	public class LandlordNeedsAccessToVillageCommonsIssueBehavior : CampaignBehaviorBase
	{
		// Token: 0x06002D49 RID: 11593 RVA: 0x000BD924 File Offset: 0x000BBB24
		public override void RegisterEvents()
		{
			CampaignEvents.OnCheckForIssueEvent.AddNonSerializedListener(this, new Action<Hero>(this.OnCheckForIssue));
		}

		// Token: 0x06002D4A RID: 11594 RVA: 0x000BD93D File Offset: 0x000BBB3D
		public override void SyncData(IDataStore dataStore)
		{
		}

		// Token: 0x06002D4B RID: 11595 RVA: 0x000BD940 File Offset: 0x000BBB40
		public void OnCheckForIssue(Hero hero)
		{
			if (this.ConditionsHold(hero))
			{
				Campaign.Current.IssueManager.AddPotentialIssueData(hero, new PotentialIssueData(new PotentialIssueData.StartIssueDelegate(this.OnSelected), typeof(LandlordNeedsAccessToVillageCommonsIssueBehavior.LandlordNeedsAccessToVillageCommonsIssue), IssueBase.IssueFrequency.Common, null));
				return;
			}
			Campaign.Current.IssueManager.AddPotentialIssueData(hero, new PotentialIssueData(typeof(LandlordNeedsAccessToVillageCommonsIssueBehavior.LandlordNeedsAccessToVillageCommonsIssue), IssueBase.IssueFrequency.Common));
		}

		// Token: 0x06002D4C RID: 11596 RVA: 0x000BD9A4 File Offset: 0x000BBBA4
		private bool ConditionsHold(Hero issueGiver)
		{
			return issueGiver.CurrentSettlement != null && issueGiver.CurrentSettlement.IsVillage && !issueGiver.CurrentSettlement.IsUnderRaid && issueGiver.CurrentSettlement.Village.VillageType == DefaultVillageTypes.WheatFarm && issueGiver.IsRuralNotable && !Clan.BanditFactions.IsEmpty<Clan>() && issueGiver.GetTraitLevel(DefaultTraits.Mercy) <= 0 && issueGiver.GetTraitLevel(DefaultTraits.Generosity) <= 0 && issueGiver.CurrentSettlement.Village.Bound.Town.Security <= 70f && issueGiver.CurrentSettlement.Village.Bound.BoundVillages.Any(delegate(Village x)
			{
				if (x.Settlement != issueGiver.CurrentSettlement && !x.Settlement.IsUnderRaid)
				{
					return x.Settlement.Notables.Any((Hero notable) => notable.IsHeadman && notable.CanHaveQuestsOrIssues());
				}
				return false;
			});
		}

		// Token: 0x06002D4D RID: 11597 RVA: 0x000BDAAC File Offset: 0x000BBCAC
		private IssueBase OnSelected(in PotentialIssueData pid, Hero issueOwner)
		{
			return new LandlordNeedsAccessToVillageCommonsIssueBehavior.LandlordNeedsAccessToVillageCommonsIssue(issueOwner);
		}

		// Token: 0x04000D91 RID: 3473
		private const IssueBase.IssueFrequency LandlordNeedsAccessToVillageCommonsIssueFrequency = IssueBase.IssueFrequency.Common;

		// Token: 0x02000639 RID: 1593
		public class LandlordNeedsAccessToVillageCommonsIssue : IssueBase
		{
			// Token: 0x06004E08 RID: 19976 RVA: 0x001651EB File Offset: 0x001633EB
			internal static void AutoGeneratedStaticCollectObjectsLandlordNeedsAccessToVillageCommonsIssue(object o, List<object> collectedObjects)
			{
				((LandlordNeedsAccessToVillageCommonsIssueBehavior.LandlordNeedsAccessToVillageCommonsIssue)o).AutoGeneratedInstanceCollectObjects(collectedObjects);
			}

			// Token: 0x06004E09 RID: 19977 RVA: 0x001651F9 File Offset: 0x001633F9
			protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
			{
				base.AutoGeneratedInstanceCollectObjects(collectedObjects);
				collectedObjects.Add(this._targetSettlement);
			}

			// Token: 0x06004E0A RID: 19978 RVA: 0x0016520E File Offset: 0x0016340E
			internal static object AutoGeneratedGetMemberValue_targetSettlement(object o)
			{
				return ((LandlordNeedsAccessToVillageCommonsIssueBehavior.LandlordNeedsAccessToVillageCommonsIssue)o)._targetSettlement;
			}

			// Token: 0x17001008 RID: 4104
			// (get) Token: 0x06004E0B RID: 19979 RVA: 0x0016521B File Offset: 0x0016341B
			public override IssueBase.AlternativeSolutionScaleFlag AlternativeSolutionScaleFlags
			{
				get
				{
					return IssueBase.AlternativeSolutionScaleFlag.Casualties | IssueBase.AlternativeSolutionScaleFlag.FailureRisk;
				}
			}

			// Token: 0x17001009 RID: 4105
			// (get) Token: 0x06004E0C RID: 19980 RVA: 0x0016521F File Offset: 0x0016341F
			public override int AlternativeSolutionBaseNeededMenCount
			{
				get
				{
					return 3 + MathF.Ceiling(4f + base.IssueDifficultyMultiplier);
				}
			}

			// Token: 0x1700100A RID: 4106
			// (get) Token: 0x06004E0D RID: 19981 RVA: 0x00165234 File Offset: 0x00163434
			protected override int AlternativeSolutionBaseDurationInDaysInternal
			{
				get
				{
					return 2 + MathF.Ceiling(4f + base.IssueDifficultyMultiplier);
				}
			}

			// Token: 0x1700100B RID: 4107
			// (get) Token: 0x06004E0E RID: 19982 RVA: 0x00165249 File Offset: 0x00163449
			protected override int RewardGold
			{
				get
				{
					return (int)(250f + 1000f * base.IssueDifficultyMultiplier);
				}
			}

			// Token: 0x1700100C RID: 4108
			// (get) Token: 0x06004E0F RID: 19983 RVA: 0x00165260 File Offset: 0x00163460
			protected override TextObject AlternativeSolutionStartLog
			{
				get
				{
					TextObject textObject = new TextObject("{=6OKW8Ba3}{ISSUE_GIVER.LINK}, a landowner from {ISSUE_GIVER_SETTLEMENT}, has told you about {?ISSUE_GIVER.GENDER}her{?}his{\\?} problems with the herders of {TARGET_SETTLEMENT}. Apparently {?ISSUE_GIVER.GENDER}she{?}he{\\?} purchased the right to use a pasture near the village. But some local herders refuse to clear out and are causing problems for {?ISSUE_GIVER.GENDER}her{?}his{\\?} herdsmen. You have agreed to send {COMPANION.LINK} along with {NEEDED_MEN_COUNT} of your men to take care of the situation. You expect them to return in {RETURN_DAYS} days.", null);
					StringHelpers.SetCharacterProperties("COMPANION", base.AlternativeSolutionHero.CharacterObject, textObject, false);
					StringHelpers.SetCharacterProperties("ISSUE_GIVER", base.IssueOwner.CharacterObject, textObject, false);
					textObject.SetTextVariable("ISSUE_GIVER_SETTLEMENT", base.IssueOwner.CurrentSettlement.EncyclopediaLinkWithName);
					textObject.SetTextVariable("TARGET_SETTLEMENT", this._targetSettlement.EncyclopediaLinkWithName);
					textObject.SetTextVariable("NEEDED_MEN_COUNT", this.AlternativeSolutionSentTroops.TotalManCount - 1);
					textObject.SetTextVariable("RETURN_DAYS", base.GetTotalAlternativeSolutionDurationInDays());
					return textObject;
				}
			}

			// Token: 0x1700100D RID: 4109
			// (get) Token: 0x06004E10 RID: 19984 RVA: 0x00165308 File Offset: 0x00163508
			public override TextObject Title
			{
				get
				{
					TextObject textObject = new TextObject("{=jYHKGhnc}Landlord needs access to the {TARGET_SETTLEMENT} commons", null);
					textObject.SetTextVariable("TARGET_SETTLEMENT", this._targetSettlement.Name);
					return textObject;
				}
			}

			// Token: 0x1700100E RID: 4110
			// (get) Token: 0x06004E11 RID: 19985 RVA: 0x0016532C File Offset: 0x0016352C
			public override TextObject Description
			{
				get
				{
					TextObject textObject = new TextObject("{=XXac5fMa}A landowner needs your help in a dispute with herders from nearby {TARGET_SETTLEMENT}. They won't let {?ISSUE_GIVER.GENDER}her{?}his{\\?} herdsmen use pastures {?ISSUE_GIVER.GENDER}she{?}he{\\?} bought.", null);
					textObject.SetTextVariable("TARGET_SETTLEMENT", this._targetSettlement.Name);
					return textObject;
				}
			}

			// Token: 0x1700100F RID: 4111
			// (get) Token: 0x06004E12 RID: 19986 RVA: 0x00165350 File Offset: 0x00163550
			public override TextObject IssueAsRumorInSettlement
			{
				get
				{
					TextObject textObject = new TextObject("{=nxyXKy2z}Old {QUEST_GIVER.NAME} has got some problems with those herders over in {TARGET_SETTLEMENT}.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.IssueOwner.CharacterObject, textObject, false);
					textObject.SetTextVariable("TARGET_SETTLEMENT", this._targetSettlement.Name);
					return textObject;
				}
			}

			// Token: 0x17001010 RID: 4112
			// (get) Token: 0x06004E13 RID: 19987 RVA: 0x0016539C File Offset: 0x0016359C
			public override TextObject IssueBriefByIssueGiver
			{
				get
				{
					TextObject textObject = new TextObject("{=DUB6zfSe}I have a bit of a dispute with {TARGET_SETTLEMENT}. I recently purchased the right to graze cattle in the nearby pastures from a landowner there. But now some of the herders are making problems.[if:convo_thinking][ib:closed]", null);
					if (base.IssueOwner.CharacterObject.GetPersona() == DefaultTraits.PersonaCurt)
					{
						textObject = new TextObject("{=0TyPBryV}I recently bought the right to graze cattle near the village of {TARGET_SETTLEMENT}. Good pastureland is hard to find. But now the locals are giving my herdsmen trouble.[if:convo_thinking][ib:closed]", null);
					}
					textObject.SetTextVariable("TARGET_SETTLEMENT", this._targetSettlement.Name);
					return textObject;
				}
			}

			// Token: 0x17001011 RID: 4113
			// (get) Token: 0x06004E14 RID: 19988 RVA: 0x001653F0 File Offset: 0x001635F0
			public override TextObject IssueAcceptByPlayer
			{
				get
				{
					return new TextObject("{=TXDjKUNf}What's the problem?", null);
				}
			}

			// Token: 0x17001012 RID: 4114
			// (get) Token: 0x06004E15 RID: 19989 RVA: 0x00165400 File Offset: 0x00163600
			public override TextObject IssueQuestSolutionExplanationByIssueGiver
			{
				get
				{
					TextObject result = new TextObject("{=Je7SWXK3}They claim that I don't have the right to graze there, that village land can't be bought and sold like that. But look, I spent my silver. I won't get it back. Meanwhile, I can't afford to wait. I need someone to ride along with my herdsmen and my cattle can graze, one way or the other, even if it means violence. I can't let my herd just starve.[if:convo_bored][ib:hip]", null);
					if (base.IssueOwner.CharacterObject.GetPersona() == DefaultTraits.PersonaCurt)
					{
						result = new TextObject("{=5ehlbXm6}They don't want to share the pastures. But I spent my silver, and I hold the title deed. I need someone to ride along with my herdsmen and clear off anyone who gets in their way.[if:convo_stern][ib:hip]", null);
					}
					return result;
				}
			}

			// Token: 0x17001013 RID: 4115
			// (get) Token: 0x06004E16 RID: 19990 RVA: 0x00165440 File Offset: 0x00163640
			public override TextObject IssueAlternativeSolutionExplanationByIssueGiver
			{
				get
				{
					TextObject textObject = new TextObject("{=wodLHjnh}You or one of your companions with some {ALTERNATIVE_TROOP_AMOUNT} men should do the job. Either way I am willing to pay you {REWARD}{GOLD_ICON}. I doubt they'd stand up long to real warriors.[if:convo_mocking_teasing][ib:closed2]", null);
					textObject.SetTextVariable("REWARD", this.RewardGold);
					textObject.SetTextVariable("ALTERNATIVE_TROOP_AMOUNT", base.GetTotalAlternativeSolutionNeededMenCount());
					textObject.SetTextVariable("GOLD_ICON", "{=!}<img src=\"General\\Icons\\Coin@2x\" extend=\"8\">");
					return textObject;
				}
			}

			// Token: 0x17001014 RID: 4116
			// (get) Token: 0x06004E17 RID: 19991 RVA: 0x0016548D File Offset: 0x0016368D
			public override bool IsThereAlternativeSolution
			{
				get
				{
					return true;
				}
			}

			// Token: 0x17001015 RID: 4117
			// (get) Token: 0x06004E18 RID: 19992 RVA: 0x00165490 File Offset: 0x00163690
			public override bool IsThereLordSolution
			{
				get
				{
					return false;
				}
			}

			// Token: 0x17001016 RID: 4118
			// (get) Token: 0x06004E19 RID: 19993 RVA: 0x00165493 File Offset: 0x00163693
			public override TextObject IssueQuestSolutionAcceptByPlayer
			{
				get
				{
					return new TextObject("{=GOkjJwZr}I can get your herdsmen to the pastures.", null);
				}
			}

			// Token: 0x17001017 RID: 4119
			// (get) Token: 0x06004E1A RID: 19994 RVA: 0x001654A0 File Offset: 0x001636A0
			public override TextObject IssueAlternativeSolutionAcceptByPlayer
			{
				get
				{
					TextObject textObject = new TextObject("{=QO0EX2O3}Sure. I can order one of my companions and {TROOP_AMOUNT} men to escort your herds to pasture in {TARGET_SETTLEMENT}.", null);
					textObject.SetTextVariable("TROOP_AMOUNT", base.GetTotalAlternativeSolutionNeededMenCount());
					textObject.SetTextVariable("TARGET_SETTLEMENT", this._targetSettlement.Name);
					return textObject;
				}
			}

			// Token: 0x17001018 RID: 4120
			// (get) Token: 0x06004E1B RID: 19995 RVA: 0x001654D6 File Offset: 0x001636D6
			public override TextObject IssueDiscussAlternativeSolution
			{
				get
				{
					TextObject textObject = new TextObject("{=BH17ZNSe}I don't think we'll have any more problems at {TARGET_SETTLEMENT}, thanks to your men. Please give them our thanks, {?PLAYER.GENDER}madam{?}sir{\\?}.[if:convo_mocking_teasing][ib:hip]", null);
					textObject.SetTextVariable("TARGET_SETTLEMENT", this._targetSettlement.Name);
					return textObject;
				}
			}

			// Token: 0x17001019 RID: 4121
			// (get) Token: 0x06004E1C RID: 19996 RVA: 0x001654FC File Offset: 0x001636FC
			public override TextObject IssueAlternativeSolutionResponseByIssueGiver
			{
				get
				{
					TextObject textObject = new TextObject("{=8INOZiew}Thank you, [if:convo_normal][ib:confident]both for looking out for my interests and upholding the law.", null);
					if (base.IssueOwner.CharacterObject.GetPersona() == DefaultTraits.PersonaCurt)
					{
						textObject = new TextObject("{=UsuOXc25}Thanks. [if:convo_stern][ib:closed]Show those troublemakers that the law is the law.", null);
					}
					StringHelpers.SetCharacterProperties("PLAYER", CharacterObject.PlayerCharacter, textObject, false);
					return textObject;
				}
			}

			// Token: 0x1700101A RID: 4122
			// (get) Token: 0x06004E1D RID: 19997 RVA: 0x0016554B File Offset: 0x0016374B
			protected override int CompanionSkillRewardXP
			{
				get
				{
					return (int)(700f + 900f * base.IssueDifficultyMultiplier);
				}
			}

			// Token: 0x06004E1E RID: 19998 RVA: 0x00165560 File Offset: 0x00163760
			public LandlordNeedsAccessToVillageCommonsIssue(Hero issueOwner) : base(issueOwner, CampaignTime.DaysFromNow(15f))
			{
			}

			// Token: 0x06004E1F RID: 19999 RVA: 0x00165573 File Offset: 0x00163773
			protected override float GetIssueEffectAmountInternal(IssueEffect issueEffect)
			{
				if (issueEffect == DefaultIssueEffects.SettlementSecurity)
				{
					return -1f;
				}
				if (issueEffect == DefaultIssueEffects.IssueOwnerPower)
				{
					return -0.1f;
				}
				return 0f;
			}

			// Token: 0x06004E20 RID: 20000 RVA: 0x00165598 File Offset: 0x00163798
			public override ValueTuple<SkillObject, int> GetAlternativeSolutionSkill(Hero hero)
			{
				int skillValue = hero.GetSkillValue(DefaultSkills.OneHanded);
				int skillValue2 = hero.GetSkillValue(DefaultSkills.TwoHanded);
				int skillValue3 = hero.GetSkillValue(DefaultSkills.Polearm);
				if (skillValue >= skillValue2 && skillValue >= skillValue3)
				{
					return new ValueTuple<SkillObject, int>(DefaultSkills.OneHanded, 150);
				}
				return new ValueTuple<SkillObject, int>((skillValue2 >= skillValue3) ? DefaultSkills.TwoHanded : DefaultSkills.Polearm, 150);
			}

			// Token: 0x06004E21 RID: 20001 RVA: 0x001655FB File Offset: 0x001637FB
			public override bool AlternativeSolutionCondition(out TextObject explanation)
			{
				explanation = TextObject.Empty;
				return QuestHelper.CheckRosterForAlternativeSolution(MobileParty.MainParty.MemberRoster, base.GetTotalAlternativeSolutionNeededMenCount(), ref explanation, 2, false);
			}

			// Token: 0x06004E22 RID: 20002 RVA: 0x0016561C File Offset: 0x0016381C
			protected override void AlternativeSolutionEndWithSuccessConsequence()
			{
				this.ApplySuccessRewards();
			}

			// Token: 0x06004E23 RID: 20003 RVA: 0x00165624 File Offset: 0x00163824
			protected override void AlternativeSolutionEndWithFailureConsequence()
			{
				this.ApplyFailRewards();
			}

			// Token: 0x06004E24 RID: 20004 RVA: 0x0016562C File Offset: 0x0016382C
			private void ApplySuccessRewards()
			{
				base.IssueOwner.AddPower(10f);
				ChangeRelationAction.ApplyPlayerRelation(base.IssueOwner, 5, true, true);
				TraitLevelingHelper.OnIssueSolvedThroughQuest(base.IssueOwner, new Tuple<TraitObject, int>[]
				{
					new Tuple<TraitObject, int>(DefaultTraits.Honor, 30),
					new Tuple<TraitObject, int>(DefaultTraits.Mercy, -20)
				});
				foreach (Hero hero in this._targetSettlement.Notables)
				{
					if (hero.IsHeadman)
					{
						ChangeRelationAction.ApplyPlayerRelation(hero, -3, true, true);
						hero.AddPower(-10f);
					}
				}
			}

			// Token: 0x06004E25 RID: 20005 RVA: 0x001656E8 File Offset: 0x001638E8
			private void ApplyFailRewards()
			{
				base.IssueOwner.AddPower(-10f);
				ChangeRelationAction.ApplyPlayerRelation(base.IssueOwner, -5, true, true);
				TraitLevelingHelper.OnIssueSolvedThroughQuest(base.IssueOwner, new Tuple<TraitObject, int>[]
				{
					new Tuple<TraitObject, int>(DefaultTraits.Honor, -20)
				});
				foreach (Hero hero in this._targetSettlement.Notables)
				{
					if (hero.IsHeadman)
					{
						ChangeRelationAction.ApplyPlayerRelation(hero, 3, true, true);
						hero.AddPower(10f);
					}
				}
			}

			// Token: 0x06004E26 RID: 20006 RVA: 0x00165794 File Offset: 0x00163994
			public override bool DoTroopsSatisfyAlternativeSolution(TroopRoster troopRoster, out TextObject explanation)
			{
				explanation = TextObject.Empty;
				return QuestHelper.CheckRosterForAlternativeSolution(troopRoster, base.GetTotalAlternativeSolutionNeededMenCount(), ref explanation, 2, false);
			}

			// Token: 0x06004E27 RID: 20007 RVA: 0x001657AC File Offset: 0x001639AC
			public override bool IsTroopTypeNeededByAlternativeSolution(CharacterObject character)
			{
				return character.Tier >= 2;
			}

			// Token: 0x06004E28 RID: 20008 RVA: 0x001657BA File Offset: 0x001639BA
			protected override void AfterIssueCreation()
			{
				Village village = base.IssueOwner.CurrentSettlement.Village.Bound.BoundVillages.FirstOrDefault(delegate(Village x)
				{
					if (x.Settlement != base.IssueOwner.CurrentSettlement && !x.Settlement.IsUnderRaid)
					{
						return x.Settlement.Notables.Any((Hero notable) => notable.IsHeadman);
					}
					return false;
				});
				this._targetSettlement = ((village != null) ? village.Settlement : null);
			}

			// Token: 0x06004E29 RID: 20009 RVA: 0x001657F9 File Offset: 0x001639F9
			protected override void OnGameLoad()
			{
			}

			// Token: 0x06004E2A RID: 20010 RVA: 0x001657FB File Offset: 0x001639FB
			protected override void HourlyTick()
			{
			}

			// Token: 0x06004E2B RID: 20011 RVA: 0x001657FD File Offset: 0x001639FD
			protected override QuestBase GenerateIssueQuest(string questId)
			{
				return new LandlordNeedsAccessToVillageCommonsIssueBehavior.LandlordNeedsAccessToVillageCommonsIssueQuest(questId, base.IssueOwner, CampaignTime.DaysFromNow(6f), this._targetSettlement, this.RewardGold, base.IssueDifficultyMultiplier);
			}

			// Token: 0x06004E2C RID: 20012 RVA: 0x00165827 File Offset: 0x00163A27
			public override IssueBase.IssueFrequency GetFrequency()
			{
				return IssueBase.IssueFrequency.Common;
			}

			// Token: 0x06004E2D RID: 20013 RVA: 0x0016582C File Offset: 0x00163A2C
			protected override bool CanPlayerTakeQuestConditions(Hero issueGiver, out IssueBase.PreconditionFlags flag, out Hero relationHero, out SkillObject skill)
			{
				skill = null;
				relationHero = null;
				flag = IssueBase.PreconditionFlags.None;
				if (issueGiver.GetRelationWithPlayer() < -10f)
				{
					flag |= IssueBase.PreconditionFlags.Relation;
					relationHero = issueGiver;
				}
				if (base.IssueOwner.MapFaction.IsAtWarWith(Hero.MainHero.MapFaction))
				{
					flag |= IssueBase.PreconditionFlags.AtWar;
				}
				if (MobileParty.MainParty.MemberRoster.TotalHealthyCount < 10)
				{
					flag |= IssueBase.PreconditionFlags.NotEnoughTroops;
				}
				return flag == IssueBase.PreconditionFlags.None;
			}

			// Token: 0x06004E2E RID: 20014 RVA: 0x001658A0 File Offset: 0x00163AA0
			public override bool IssueStayAliveConditions()
			{
				if (!base.IssueOwner.CurrentSettlement.IsRaided && !base.IssueOwner.CurrentSettlement.IsUnderRaid && base.IssueOwner.CurrentSettlement.Village.Bound.Town.Security <= 90f)
				{
					if (this._targetSettlement.Notables.Any((Hero x) => x.IsHeadman))
					{
						return !Clan.BanditFactions.IsEmpty<Clan>();
					}
				}
				return false;
			}

			// Token: 0x06004E2F RID: 20015 RVA: 0x00165937 File Offset: 0x00163B37
			protected override void CompleteIssueWithTimedOutConsequences()
			{
			}

			// Token: 0x04001A11 RID: 6673
			private const int AlternativeSolutionTroopTierRequirement = 2;

			// Token: 0x04001A12 RID: 6674
			private const int MinimumRequiredMenCount = 10;

			// Token: 0x04001A13 RID: 6675
			private const int NeededCompanionSkill = 150;

			// Token: 0x04001A14 RID: 6676
			private const int IssueDuration = 15;

			// Token: 0x04001A15 RID: 6677
			private const int QuestTimeLimit = 6;

			// Token: 0x04001A16 RID: 6678
			[SaveableField(100)]
			private Settlement _targetSettlement;
		}

		// Token: 0x0200063A RID: 1594
		public class LandlordNeedsAccessToVillageCommonsIssueQuest : QuestBase
		{
			// Token: 0x06004E31 RID: 20017 RVA: 0x0016599A File Offset: 0x00163B9A
			internal static void AutoGeneratedStaticCollectObjectsLandlordNeedsAccessToVillageCommonsIssueQuest(object o, List<object> collectedObjects)
			{
				((LandlordNeedsAccessToVillageCommonsIssueBehavior.LandlordNeedsAccessToVillageCommonsIssueQuest)o).AutoGeneratedInstanceCollectObjects(collectedObjects);
			}

			// Token: 0x06004E32 RID: 20018 RVA: 0x001659A8 File Offset: 0x00163BA8
			protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
			{
				base.AutoGeneratedInstanceCollectObjects(collectedObjects);
				collectedObjects.Add(this._rivalMobileParty);
				collectedObjects.Add(this._targetSettlement);
				collectedObjects.Add(this._herdersMobileParty);
				collectedObjects.Add(this._headmanNotable);
			}

			// Token: 0x06004E33 RID: 20019 RVA: 0x001659E1 File Offset: 0x00163BE1
			internal static object AutoGeneratedGetMemberValue_rivalMobileParty(object o)
			{
				return ((LandlordNeedsAccessToVillageCommonsIssueBehavior.LandlordNeedsAccessToVillageCommonsIssueQuest)o)._rivalMobileParty;
			}

			// Token: 0x06004E34 RID: 20020 RVA: 0x001659EE File Offset: 0x00163BEE
			internal static object AutoGeneratedGetMemberValue_targetSettlement(object o)
			{
				return ((LandlordNeedsAccessToVillageCommonsIssueBehavior.LandlordNeedsAccessToVillageCommonsIssueQuest)o)._targetSettlement;
			}

			// Token: 0x06004E35 RID: 20021 RVA: 0x001659FB File Offset: 0x00163BFB
			internal static object AutoGeneratedGetMemberValue_herdersMobileParty(object o)
			{
				return ((LandlordNeedsAccessToVillageCommonsIssueBehavior.LandlordNeedsAccessToVillageCommonsIssueQuest)o)._herdersMobileParty;
			}

			// Token: 0x06004E36 RID: 20022 RVA: 0x00165A08 File Offset: 0x00163C08
			internal static object AutoGeneratedGetMemberValue_issueDifficultyMultiplier(object o)
			{
				return ((LandlordNeedsAccessToVillageCommonsIssueBehavior.LandlordNeedsAccessToVillageCommonsIssueQuest)o)._issueDifficultyMultiplier;
			}

			// Token: 0x06004E37 RID: 20023 RVA: 0x00165A1A File Offset: 0x00163C1A
			internal static object AutoGeneratedGetMemberValue_headmanNotable(object o)
			{
				return ((LandlordNeedsAccessToVillageCommonsIssueBehavior.LandlordNeedsAccessToVillageCommonsIssueQuest)o)._headmanNotable;
			}

			// Token: 0x06004E38 RID: 20024 RVA: 0x00165A27 File Offset: 0x00163C27
			internal static object AutoGeneratedGetMemberValue_questId(object o)
			{
				return ((LandlordNeedsAccessToVillageCommonsIssueBehavior.LandlordNeedsAccessToVillageCommonsIssueQuest)o)._questId;
			}

			// Token: 0x06004E39 RID: 20025 RVA: 0x00165A34 File Offset: 0x00163C34
			internal static object AutoGeneratedGetMemberValue_rewardGold(object o)
			{
				return ((LandlordNeedsAccessToVillageCommonsIssueBehavior.LandlordNeedsAccessToVillageCommonsIssueQuest)o)._rewardGold;
			}

			// Token: 0x06004E3A RID: 20026 RVA: 0x00165A46 File Offset: 0x00163C46
			internal static object AutoGeneratedGetMemberValue_rivalPartySpawnDeltaTime(object o)
			{
				return ((LandlordNeedsAccessToVillageCommonsIssueBehavior.LandlordNeedsAccessToVillageCommonsIssueQuest)o)._rivalPartySpawnDeltaTime;
			}

			// Token: 0x06004E3B RID: 20027 RVA: 0x00165A58 File Offset: 0x00163C58
			internal static object AutoGeneratedGetMemberValue_battleStarted(object o)
			{
				return ((LandlordNeedsAccessToVillageCommonsIssueBehavior.LandlordNeedsAccessToVillageCommonsIssueQuest)o)._battleStarted;
			}

			// Token: 0x06004E3C RID: 20028 RVA: 0x00165A6A File Offset: 0x00163C6A
			internal static object AutoGeneratedGetMemberValue_spawnRivalPartyAfterHours(object o)
			{
				return ((LandlordNeedsAccessToVillageCommonsIssueBehavior.LandlordNeedsAccessToVillageCommonsIssueQuest)o)._spawnRivalPartyAfterHours;
			}

			// Token: 0x1700101B RID: 4123
			// (get) Token: 0x06004E3D RID: 20029 RVA: 0x00165A7C File Offset: 0x00163C7C
			public sealed override TextObject Title
			{
				get
				{
					TextObject textObject = new TextObject("{=oT8DUcHf}Landowner needs {TARGET_SETTLEMENT}'s pasture", null);
					textObject.SetTextVariable("TARGET_SETTLEMENT", this._targetSettlement.Name);
					return textObject;
				}
			}

			// Token: 0x1700101C RID: 4124
			// (get) Token: 0x06004E3E RID: 20030 RVA: 0x00165AA0 File Offset: 0x00163CA0
			public override bool IsRemainingTimeHidden
			{
				get
				{
					return false;
				}
			}

			// Token: 0x1700101D RID: 4125
			// (get) Token: 0x06004E3F RID: 20031 RVA: 0x00165AA4 File Offset: 0x00163CA4
			private TextObject _playerStartsQuestLogText
			{
				get
				{
					TextObject textObject = new TextObject("{=GyZHauax}{QUEST_GIVER.LINK}, a rural landowner, has told you about {?QUEST_GIVER.GENDER}her{?}his{\\?} problems with the local herders of {TARGET_SETTLEMENT}. Apparently {?QUEST_GIVER.GENDER}she{?}he{\\?} purchased the right to use a nearby pasture. But the local herders of {TARGET_SETTLEMENT} refuse to clear out and are causing problems for {?QUEST_GIVER.GENDER}her{?}his{\\?} herdsmen. You agreed to do the job yourself, and escort herders to pasture.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					textObject.SetTextVariable("QUEST_GIVER_SETTLEMENT", base.QuestGiver.CurrentSettlement.EncyclopediaLinkWithName);
					textObject.SetTextVariable("TARGET_SETTLEMENT", this._targetSettlement.EncyclopediaLinkWithName);
					return textObject;
				}
			}

			// Token: 0x1700101E RID: 4126
			// (get) Token: 0x06004E40 RID: 20032 RVA: 0x00165B0C File Offset: 0x00163D0C
			private TextObject _successWitHVillagerSurrenderQuestLogText
			{
				get
				{
					TextObject textObject = new TextObject("{=avMQKUoJ}You were able to drive the herders from the disputed pasture. The landowner {QUEST_GIVER.LINK}. {?QUEST_GIVER.GENDER}She{?}he{\\?} is grateful and sends {REWARD}{GOLD_ICON} with {?QUEST_GIVER.GENDER}her{?}his{\\?} regards.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					textObject.SetTextVariable("GOLD_ICON", "{=!}<img src=\"General\\Icons\\Coin@2x\" extend=\"8\">");
					textObject.SetTextVariable("REWARD", this._rewardGold);
					return textObject;
				}
			}

			// Token: 0x1700101F RID: 4127
			// (get) Token: 0x06004E41 RID: 20033 RVA: 0x00165B64 File Offset: 0x00163D64
			private TextObject _successWitHWinningTheFightQuestLogText
			{
				get
				{
					TextObject textObject = new TextObject("{=YbBObxLH}You were able to drive the herders from the disputed pasture. The landowner, {QUEST_GIVER.LINK}, is grateful and sends {REWARD}{GOLD_ICON} with {?QUEST_GIVER.GENDER}her{?}his{\\?} regards.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					textObject.SetTextVariable("QUEST_GIVER_SETTLEMENT", base.QuestGiver.CurrentSettlement.EncyclopediaLinkWithName);
					textObject.SetTextVariable("GOLD_ICON", "{=!}<img src=\"General\\Icons\\Coin@2x\" extend=\"8\">");
					textObject.SetTextVariable("REWARD", this._rewardGold);
					return textObject;
				}
			}

			// Token: 0x17001020 RID: 4128
			// (get) Token: 0x06004E42 RID: 20034 RVA: 0x00165BD8 File Offset: 0x00163DD8
			private TextObject _failWithLosingTheFightQuestLogText
			{
				get
				{
					TextObject textObject = new TextObject("{=117W31dZ}You were unable to drive the herders from the disputed pasture. The landowner, {QUEST_GIVER.LINK}, probably feels that you let {?QUEST_GIVER.GENDER}her{?}him{\\?} down.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					textObject.SetTextVariable("QUEST_GIVER_SETTLEMENT", base.QuestGiver.CurrentSettlement.EncyclopediaLinkWithName);
					return textObject;
				}
			}

			// Token: 0x17001021 RID: 4129
			// (get) Token: 0x06004E43 RID: 20035 RVA: 0x00165C28 File Offset: 0x00163E28
			private TextObject _failWithCounterOfferLogText
			{
				get
				{
					TextObject textObject = new TextObject("{=zJujFbXU}You decided that the herders had more right to the disputed pasture than the landowner, {QUEST_GIVER.LINK}. {?QUEST_GIVER.GENDER}She{?}He{\\?} probably feels betrayed.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					textObject.SetTextVariable("QUEST_GIVER_SETTLEMENT", base.QuestGiver.CurrentSettlement.EncyclopediaLinkWithName);
					return textObject;
				}
			}

			// Token: 0x17001022 RID: 4130
			// (get) Token: 0x06004E44 RID: 20036 RVA: 0x00165C78 File Offset: 0x00163E78
			private TextObject _failByTimeoutLogText
			{
				get
				{
					TextObject textObject = new TextObject("{=ja74aAEI}You ignored the herders and did not solve the dispute. {?QUEST_GIVER.GENDER}She{?}he{\\?} probably feels betrayed.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x17001023 RID: 4131
			// (get) Token: 0x06004E45 RID: 20037 RVA: 0x00165CAC File Offset: 0x00163EAC
			private TextObject _targetVillageRaided
			{
				get
				{
					TextObject textObject = new TextObject("{=aN85Kfnq}{SETTLEMENT} was raided. Your agreement with {QUEST_GIVER.LINK} is canceled.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					textObject.SetTextVariable("SETTLEMENT", this._targetSettlement.EncyclopediaLinkWithName);
					return textObject;
				}
			}

			// Token: 0x17001024 RID: 4132
			// (get) Token: 0x06004E46 RID: 20038 RVA: 0x00165CF8 File Offset: 0x00163EF8
			private TextObject _playerDeclaredWarQuestLogText
			{
				get
				{
					TextObject textObject = new TextObject("{=bqeWVVEE}Your actions have started a war with {QUEST_GIVER.LINK}'s faction. {?QUEST_GIVER.GENDER}She{?}He{\\?} cancels your agreement and the quest is a failure.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x17001025 RID: 4133
			// (get) Token: 0x06004E47 RID: 20039 RVA: 0x00165D2A File Offset: 0x00163F2A
			private TextObject _warDeclaredCancelLog
			{
				get
				{
					return new TextObject("{=wQH1N109}War broke out between your clan and the quest giver's realm. Quest canceled.", null);
				}
			}

			// Token: 0x06004E48 RID: 20040 RVA: 0x00165D38 File Offset: 0x00163F38
			public LandlordNeedsAccessToVillageCommonsIssueQuest(string questId, Hero questGiver, CampaignTime duration, Settlement targetSettlement, int rewardGold, float issueDifficultyMultiplier) : base(questId, questGiver, duration, rewardGold)
			{
				this._targetSettlement = targetSettlement;
				this._headmanNotable = targetSettlement.Notables.First((Hero x) => x.IsHeadman);
				this._questId = questId;
				this._rewardGold = rewardGold;
				this._issueDifficultyMultiplier = issueDifficultyMultiplier;
				this._rivalPartySpawnDeltaTime = 0;
				this.SetDialogs();
				base.InitializeQuestOnCreation();
			}

			// Token: 0x06004E49 RID: 20041 RVA: 0x00165DB4 File Offset: 0x00163FB4
			protected override void SetDialogs()
			{
				Campaign.Current.ConversationManager.AddDialogFlow(this.GetRivalPartyDialogues(), this);
				Campaign.Current.ConversationManager.AddDialogFlow(this.GetHerderPartyNearVillageDialogues(), this);
				Campaign.Current.ConversationManager.AddDialogFlow(this.GetHerderPartyDialogues(), this);
				this.OfferDialogFlow = DialogFlow.CreateDialogFlow("issue_classic_quest_start", 100).NpcLine(new TextObject("{=qkYCWjTA}I appreciate it. I wait for the good news.", null), null, null).Condition(() => Hero.OneToOneConversationHero == base.QuestGiver).Consequence(new ConversationSentence.OnConsequenceDelegate(this.QuestAcceptedConsequences)).CloseDialog();
				this.DiscussDialogFlow = DialogFlow.CreateDialogFlow("quest_discuss", 100).NpcLine(new TextObject("{=FogJnYH9}Any news about the pastures?[if:convo_undecided_open][ib:closed]", null), null, null).Condition(() => Hero.OneToOneConversationHero == base.QuestGiver).BeginPlayerOptions().PlayerOption(new TextObject("{=wErSpkjy}I'm still working on it.", null), null).NpcLine(new TextObject("{=xolucdbr}I am glad to hear that.[if:convo_undecided_open]", null), null, null).CloseDialog().PlayerOption(new TextObject("{=7o68QryW}Not yet. I have some other business to attend to.", null), null).NpcLine(new TextObject("{=bEab8stb}Okay. I'm waiting for your good news.[if:convo_undecided_open]", null), null, null).CloseDialog().EndPlayerOptions().CloseDialog();
			}

			// Token: 0x06004E4A RID: 20042 RVA: 0x00165EE4 File Offset: 0x001640E4
			private DialogFlow GetRivalPartyDialogues()
			{
				TextObject npcText = new TextObject("{=Rt2w61N8}Don't get involved in this. [if:convo_confused_normal][ib:hip]We've grazed our herds on these hillsides since our fathers' fathers' time. We don't care if one rich bastard gave a couple of bags of silver to another rich bastard. We don't care about title deeds or courts of law or any of that. Custom is custom, and we're not going anywhere!", null);
				TextObject text = new TextObject("{=YPTZ2et7}Calm down. You're right. No one has the right to sell your ancestral lands. These herdsmen can take their cattle elsewhere.", null);
				TextObject text2 = new TextObject("{=R1W5Il2d}You can take your grievances to your lord, or to whoever sold the land. The law says a buyer has rights, and you need to clear out.", null);
				TextObject textObject = new TextObject("{=l3ALRD7c}You're just a rich bastard's lackey.[if:convo_confused_annoyed][ib:closed]", null);
				TextObject textObject2 = new TextObject("{=YLjksPbk}You're a kind {?PLAYER.GENDER}woman, [if:convo_happy]madam{?}man, sir{\\?}. You understand what poor folk like us are up against.", null);
				StringHelpers.SetCharacterProperties("PLAYER", CharacterObject.PlayerCharacter, textObject, false);
				StringHelpers.SetCharacterProperties("PLAYER", CharacterObject.PlayerCharacter, textObject2, false);
				TextObject text3 = new TextObject("{=ybb0ToHE}We will protect our lands![if:convo_thinking]", null);
				return DialogFlow.CreateDialogFlow("start", 125).NpcLine(npcText, null, null).Condition(new ConversationSentence.OnConditionDelegate(this.RivalPartyTalkOnCondition)).BeginPlayerOptions().PlayerOption(text, null).NpcLine(textObject2, null, null).Consequence(new ConversationSentence.OnConsequenceDelegate(this.FailWithAcceptingCounterOffer)).CloseDialog().PlayerOption(text2, null).EndPlayerOptions().BeginNpcOptions().NpcOption(textObject, new ConversationSentence.OnConditionDelegate(this.RivalPartySurrenderOnCondition), null, null).Consequence(new ConversationSentence.OnConsequenceDelegate(this.SuccessWithVillagersSurrender)).CloseDialog().NpcOption(text3, new ConversationSentence.OnConditionDelegate(this.RivalPartyFightOnCondition), null, null).Consequence(delegate
				{
					PlayerEncounter.LeaveEncounter = false;
				}).CloseDialog().EndNpcOptions().CloseDialog();
			}

			// Token: 0x06004E4B RID: 20043 RVA: 0x00166034 File Offset: 0x00164234
			private DialogFlow GetHerderPartyDialogues()
			{
				TextObject textObject = new TextObject("{=He6DW2Xb}Thank you for protecting us {?PLAYER.GENDER}madam{?}sir{\\?}. Keep following, we are almost there.", null);
				StringHelpers.SetCharacterProperties("PLAYER", CharacterObject.PlayerCharacter, textObject, false);
				return DialogFlow.CreateDialogFlow("start", 125).NpcLine(textObject, null, null).Condition(new ConversationSentence.OnConditionDelegate(this.HerdersTalkOnCondition)).Consequence(delegate
				{
					PlayerEncounter.LeaveEncounter = true;
				}).CloseDialog();
			}

			// Token: 0x06004E4C RID: 20044 RVA: 0x001660AD File Offset: 0x001642AD
			private bool RivalPartySurrenderOnCondition()
			{
				return MobileParty.MainParty.MemberRoster.TotalManCount - MobileParty.MainParty.MemberRoster.TotalWounded > 14;
			}

			// Token: 0x06004E4D RID: 20045 RVA: 0x001660D4 File Offset: 0x001642D4
			private DialogFlow GetHerderPartyNearVillageDialogues()
			{
				TextObject textObject = new TextObject("{=crg2DrbZ}We are worried that the herders of {TARGET_SETTLEMENT} will harm our animals. Fortunately we have you on our side {?PLAYER.GENDER}madam{?}sir{\\?}.", null);
				StringHelpers.SetCharacterProperties("PLAYER", CharacterObject.PlayerCharacter, textObject, false);
				textObject.SetTextVariable("TARGET_SETTLEMENT", this._targetSettlement.Name);
				return DialogFlow.CreateDialogFlow("start", 125).NpcLine(textObject, null, null).Condition(() => this.HerdersTalkOnCondition() && Campaign.Current.Models.MapDistanceModel.GetDistance(MobileParty.ConversationParty, this._targetSettlement) < 10f).Consequence(delegate
				{
					PlayerEncounter.LeaveEncounter = true;
				}).CloseDialog();
			}

			// Token: 0x06004E4E RID: 20046 RVA: 0x00166164 File Offset: 0x00164364
			private bool RivalPartyTalkOnCondition()
			{
				return base.IsOngoing && this._rivalMobileParty != null && CharacterObject.OneToOneConversationCharacter != null && this._rivalMobileParty.MemberRoster.Contains(CharacterObject.OneToOneConversationCharacter) && MobileParty.ConversationParty != null && !CharacterObject.OneToOneConversationCharacter.IsHero && MobileParty.ConversationParty.HomeSettlement == this._targetSettlement;
			}

			// Token: 0x06004E4F RID: 20047 RVA: 0x001661C6 File Offset: 0x001643C6
			private bool RivalPartyFightOnCondition()
			{
				return MobileParty.MainParty.MemberRoster.TotalManCount - MobileParty.MainParty.MemberRoster.TotalWounded <= 14;
			}

			// Token: 0x06004E50 RID: 20048 RVA: 0x001661F0 File Offset: 0x001643F0
			private bool HerdersTalkOnCondition()
			{
				return base.IsOngoing && this._herdersMobileParty != null && CharacterObject.OneToOneConversationCharacter != null && this._herdersMobileParty.MemberRoster.Contains(CharacterObject.OneToOneConversationCharacter) && MobileParty.ConversationParty != null && !CharacterObject.OneToOneConversationCharacter.IsHero && MobileParty.ConversationParty.Party.Owner != Hero.MainHero && MobileParty.ConversationParty.HomeSettlement == base.QuestGiver.CurrentSettlement;
			}

			// Token: 0x06004E51 RID: 20049 RVA: 0x00166270 File Offset: 0x00164470
			private void FailWithAcceptingCounterOffer()
			{
				ChangeRelationAction.ApplyPlayerRelation(this._headmanNotable, 3, true, true);
				TraitLevelingHelper.OnIssueSolvedThroughBetrayal(this._headmanNotable, new Tuple<TraitObject, int>[]
				{
					new Tuple<TraitObject, int>(DefaultTraits.Honor, -30),
					new Tuple<TraitObject, int>(DefaultTraits.Mercy, 20)
				});
				base.CompleteQuestWithFail(null);
				base.AddLog(this._failWithCounterOfferLogText, false);
				PlayerEncounter.LeaveEncounter = true;
			}

			// Token: 0x06004E52 RID: 20050 RVA: 0x001662D8 File Offset: 0x001644D8
			private void SpawnRivalParty()
			{
				Clan clan = Clan.BanditFactions.FirstOrDefault((Clan x) => !x.Culture.CanHaveSettlement);
				if (clan == null)
				{
					Settlement settlement = SettlementHelper.FindNearestHideout(null, null);
					if (settlement != null)
					{
						CultureObject banditCulture = settlement.Culture;
						clan = Clan.BanditFactions.FirstOrDefault((Clan x) => x.Culture == banditCulture);
					}
					if (clan == null)
					{
						clan = Clan.BanditFactions.GetRandomElementInefficiently<Clan>();
					}
				}
				this._rivalMobileParty = BanditPartyComponent.CreateLooterParty("villagers_of_landlord_needs_access_to_village_common_quest" + this._questId, clan, this._targetSettlement, false);
				CharacterObject villager = base.QuestGiver.Culture.Villager;
				TroopRoster troopRoster = new TroopRoster(this._rivalMobileParty.Party);
				TextObject textObject = new TextObject("{=QLLeHRWw}Herders of {QUEST_SETTLEMENT}", null);
				textObject.SetTextVariable("QUEST_SETTLEMENT", this._targetSettlement.Name);
				troopRoster.AddToCounts(villager, MathF.Ceiling(10f + 20f * this._issueDifficultyMultiplier), false, 0, 0, true, -1);
				this._rivalMobileParty.InitializeMobilePartyAtPosition(troopRoster, new TroopRoster(this._rivalMobileParty.Party), this._targetSettlement.Position2D);
				this._rivalMobileParty.InitializePartyTrade(200);
				this._rivalMobileParty.SetPartyUsedByQuest(true);
				this._rivalMobileParty.SetCustomName(textObject);
				this._rivalMobileParty.IgnoreForHours(720f);
				this._rivalMobileParty.Ai.SetDoNotMakeNewDecisions(true);
				SetPartyAiAction.GetActionForEngagingParty(this._rivalMobileParty, this._herdersMobileParty);
				this._rivalMobileParty.TargetPosition = this._herdersMobileParty.Position2D;
				this._rivalMobileParty.Party.SetVisualAsDirty();
				base.AddTrackedObject(this._rivalMobileParty);
				this._rivalMobileParty.Aggressiveness = 0f;
			}

			// Token: 0x06004E53 RID: 20051 RVA: 0x001664A9 File Offset: 0x001646A9
			private void SuccessWithVillagersSurrender()
			{
				base.CompleteQuestWithSuccess();
				base.AddLog(this._successWitHVillagerSurrenderQuestLogText, false);
				PlayerEncounter.LeaveEncounter = true;
			}

			// Token: 0x06004E54 RID: 20052 RVA: 0x001664C8 File Offset: 0x001646C8
			private void SpawnHerdersParty()
			{
				this._herdersMobileParty = MobileParty.CreateParty("rival_party_of_landlord_needs_access_to_village_common_quest" + this._questId, null, null);
				CharacterObject villager = base.QuestGiver.Culture.Villager;
				TroopRoster troopRoster = new TroopRoster(this._herdersMobileParty.Party);
				TextObject textObject = new TextObject("{=tLakpr0a}Herdsmen of {QUEST_GIVER}", null);
				textObject.SetTextVariable("QUEST_GIVER", base.QuestGiver.Name);
				troopRoster.AddToCounts(villager, MathF.Ceiling(2f + 5f * this._issueDifficultyMultiplier), false, 0, 0, true, -1);
				this._herdersMobileParty.InitializeMobilePartyAtPosition(troopRoster, new TroopRoster(this._herdersMobileParty.Party), base.QuestGiver.CurrentSettlement.Position2D);
				this._herdersMobileParty.InitializePartyTrade(200);
				this._herdersMobileParty.SetCustomName(textObject);
				this._herdersMobileParty.SetCustomHomeSettlement(base.QuestGiver.CurrentSettlement);
				this._herdersMobileParty.SetPartyUsedByQuest(true);
				this._herdersMobileParty.ItemRoster.AddToCounts(MBObjectManager.Instance.GetObject<ItemObject>("sumpter_horse"), MathF.Ceiling(2f + 5f * this._issueDifficultyMultiplier));
				this._herdersMobileParty.IgnoreForHours(720f);
				this._herdersMobileParty.Ai.SetDoNotMakeNewDecisions(true);
				this._herdersMobileParty.Party.SetVisualAsDirty();
				base.AddTrackedObject(this._herdersMobileParty);
				this._herdersMobileParty.Aggressiveness = 0f;
				Vec2 moveGoToPoint = this._targetSettlement.GetPosition2D;
				for (int i = 0; i < 15; i++)
				{
					moveGoToPoint = MobilePartyHelper.FindReachablePointAroundPosition(this._targetSettlement.GetPosition2D, 6f, 5f);
					float num;
					if (Campaign.Current.Models.MapDistanceModel.GetDistance(this._targetSettlement, moveGoToPoint, 8f, out num))
					{
						break;
					}
				}
				this._herdersMobileParty.Ai.SetMoveGoToPoint(moveGoToPoint);
				float num2;
				Campaign.Current.Models.MapDistanceModel.GetDistance(this._herdersMobileParty, moveGoToPoint, 8f, out num2);
				this._spawnRivalPartyAfterHours = (int)(num2 / this._herdersMobileParty.Speed) + 3;
			}

			// Token: 0x06004E55 RID: 20053 RVA: 0x001666F2 File Offset: 0x001648F2
			private void QuestAcceptedConsequences()
			{
				base.StartQuest();
				base.AddLog(this._playerStartsQuestLogText, false);
				base.AddTrackedObject(this._targetSettlement);
				this.SpawnHerdersParty();
			}

			// Token: 0x06004E56 RID: 20054 RVA: 0x0016671C File Offset: 0x0016491C
			protected override void OnCompleteWithSuccess()
			{
				base.QuestGiver.AddPower(10f);
				this.RelationshipChangeWithQuestGiver = 5;
				this._headmanNotable.AddPower(-10f);
				ChangeRelationAction.ApplyPlayerRelation(this._headmanNotable, -3, true, true);
				TraitLevelingHelper.OnIssueSolvedThroughQuest(base.QuestGiver, new Tuple<TraitObject, int>[]
				{
					new Tuple<TraitObject, int>(DefaultTraits.Honor, 30),
					new Tuple<TraitObject, int>(DefaultTraits.Mercy, -20)
				});
				GiveGoldAction.ApplyForQuestBetweenCharacters(null, Hero.MainHero, this._rewardGold, false);
			}

			// Token: 0x06004E57 RID: 20055 RVA: 0x001667A0 File Offset: 0x001649A0
			public override void OnFailed()
			{
				base.QuestGiver.AddPower(-10f);
				this._headmanNotable.AddPower(10f);
				this.RelationshipChangeWithQuestGiver = -5;
				TraitLevelingHelper.OnIssueFailed(base.QuestGiver, new Tuple<TraitObject, int>[]
				{
					new Tuple<TraitObject, int>(DefaultTraits.Honor, -20)
				});
			}

			// Token: 0x06004E58 RID: 20056 RVA: 0x001667F8 File Offset: 0x001649F8
			protected override void OnTimedOut()
			{
				base.QuestGiver.AddPower(-10f);
				this.RelationshipChangeWithQuestGiver = -5;
				TraitLevelingHelper.OnIssueFailed(base.QuestGiver, new Tuple<TraitObject, int>[]
				{
					new Tuple<TraitObject, int>(DefaultTraits.Honor, -20)
				});
				base.AddLog(this._failByTimeoutLogText, false);
			}

			// Token: 0x06004E59 RID: 20057 RVA: 0x0016684C File Offset: 0x00164A4C
			protected override void OnFinalize()
			{
				if (this._herdersMobileParty != null && this._herdersMobileParty.IsVisible && this._herdersMobileParty.IsActive)
				{
					DestroyPartyAction.Apply(null, this._herdersMobileParty);
				}
				if (this._rivalMobileParty != null && this._rivalMobileParty.IsVisible && this._rivalMobileParty.IsActive)
				{
					DestroyPartyAction.Apply(null, this._rivalMobileParty);
				}
			}

			// Token: 0x06004E5A RID: 20058 RVA: 0x001668B8 File Offset: 0x00164AB8
			private void OnMapEventStarted(MapEvent mapEvent, PartyBase attackerParty, PartyBase defenderParty)
			{
				if (this._rivalMobileParty != null && mapEvent.InvolvedParties.Contains(PartyBase.MainParty) && mapEvent.InvolvedParties.Contains(this._rivalMobileParty.Party) && !mapEvent.InvolvedParties.Contains(this._herdersMobileParty.Party))
				{
					this._herdersMobileParty.Party.MapEventSide = PartyBase.MainParty.MapEventSide;
				}
				if (QuestHelper.CheckMinorMajorCoercion(this, mapEvent, attackerParty))
				{
					QuestHelper.ApplyGenericMinorMajorCoercionConsequences(this, mapEvent);
				}
			}

			// Token: 0x06004E5B RID: 20059 RVA: 0x0016693C File Offset: 0x00164B3C
			private void OnMapEventEnded(MapEvent mapEvent)
			{
				if (this._rivalMobileParty != null && ((mapEvent.InvolvedParties.Contains(PartyBase.MainParty) && mapEvent.InvolvedParties.Contains(this._rivalMobileParty.Party)) || (mapEvent.InvolvedParties.Contains(PartyBase.MainParty) && mapEvent.InvolvedParties.Contains(this._rivalMobileParty.Party) && mapEvent.InvolvedParties.Contains(this._herdersMobileParty.Party))))
				{
					if (mapEvent.WinningSide == mapEvent.PlayerSide)
					{
						base.CompleteQuestWithSuccess();
						base.AddLog(this._successWitHWinningTheFightQuestLogText, false);
						return;
					}
					base.CompleteQuestWithFail(null);
					base.AddLog(this._failWithLosingTheFightQuestLogText, false);
				}
			}

			// Token: 0x06004E5C RID: 20060 RVA: 0x001669F8 File Offset: 0x00164BF8
			protected override void HourlyTick()
			{
				if (base.IsOngoing)
				{
					this.CheckAnSpawnRivalParty();
					if (this._rivalMobileParty != null)
					{
						MobileParty herdersMobileParty = this._herdersMobileParty;
						if (((herdersMobileParty != null) ? herdersMobileParty.MapEvent : null) == null)
						{
							MobileParty rivalMobileParty = this._rivalMobileParty;
							if (((rivalMobileParty != null) ? rivalMobileParty.MapEvent : null) == null && !this._battleStarted && Campaign.Current.Models.MapDistanceModel.GetDistance(this._rivalMobileParty, this._herdersMobileParty) < 0.25f)
							{
								EncounterManager.StartPartyEncounter(this._rivalMobileParty.Party, this._herdersMobileParty.Party);
								this._rivalMobileParty.MapEvent.IsInvulnerable = true;
								this._battleStarted = true;
							}
						}
						if (this._battleStarted && this._rivalMobileParty.MapEvent.BattleStartTime.ElapsedHoursUntilNow > 5f)
						{
							this._rivalMobileParty.MapEvent.FinalizeEvent();
							DestroyPartyAction.Apply(this._rivalMobileParty.Party, this._herdersMobileParty);
						}
					}
				}
			}

			// Token: 0x06004E5D RID: 20061 RVA: 0x00166AF8 File Offset: 0x00164CF8
			private void CheckAnSpawnRivalParty()
			{
				if (this._rivalMobileParty == null && this._rivalPartySpawnDeltaTime <= this._spawnRivalPartyAfterHours)
				{
					this._rivalPartySpawnDeltaTime++;
					if (this._rivalPartySpawnDeltaTime > this._spawnRivalPartyAfterHours)
					{
						this.SpawnRivalParty();
					}
				}
			}

			// Token: 0x06004E5E RID: 20062 RVA: 0x00166B34 File Offset: 0x00164D34
			private void OnMobilePartyDestroyed(MobileParty mobileParty, PartyBase destroyerParty)
			{
				if (base.IsOngoing)
				{
					if (mobileParty == this._rivalMobileParty && (destroyerParty == PartyBase.MainParty || destroyerParty == this._herdersMobileParty.Party))
					{
						base.AddLog(this._successWitHWinningTheFightQuestLogText, false);
						base.CompleteQuestWithSuccess();
					}
					if (mobileParty == this._herdersMobileParty)
					{
						base.AddLog(this._failWithLosingTheFightQuestLogText, false);
						base.CompleteQuestWithFail(null);
					}
				}
			}

			// Token: 0x06004E5F RID: 20063 RVA: 0x00166B9A File Offset: 0x00164D9A
			private void OnClanChangedKingdom(Clan clan, Kingdom oldKingdom, Kingdom newKingdom, ChangeKingdomAction.ChangeKingdomActionDetail detail, bool showNotification = true)
			{
				if (base.QuestGiver.CurrentSettlement.MapFaction.IsAtWarWith(Hero.MainHero.MapFaction))
				{
					base.CompleteQuestWithCancel(this._warDeclaredCancelLog);
				}
			}

			// Token: 0x06004E60 RID: 20064 RVA: 0x00166BC9 File Offset: 0x00164DC9
			private void OnWarDeclared(IFaction faction1, IFaction faction2, DeclareWarAction.DeclareWarDetail detail)
			{
				QuestHelper.CheckWarDeclarationAndFailOrCancelTheQuest(this, faction1, faction2, detail, this._playerDeclaredWarQuestLogText, this._warDeclaredCancelLog, false);
			}

			// Token: 0x06004E61 RID: 20065 RVA: 0x00166BE1 File Offset: 0x00164DE1
			protected override void InitializeQuestOnGameLoad()
			{
				this.SetDialogs();
			}

			// Token: 0x06004E62 RID: 20066 RVA: 0x00166BE9 File Offset: 0x00164DE9
			private void OnVillageRaided(Village village)
			{
				if (village == this._targetSettlement.Village)
				{
					base.AddLog(this._targetVillageRaided, false);
					base.CompleteQuestWithCancel(null);
				}
			}

			// Token: 0x06004E63 RID: 20067 RVA: 0x00166C10 File Offset: 0x00164E10
			protected override void RegisterEvents()
			{
				CampaignEvents.WarDeclared.AddNonSerializedListener(this, new Action<IFaction, IFaction, DeclareWarAction.DeclareWarDetail>(this.OnWarDeclared));
				CampaignEvents.OnClanChangedKingdomEvent.AddNonSerializedListener(this, new Action<Clan, Kingdom, Kingdom, ChangeKingdomAction.ChangeKingdomActionDetail, bool>(this.OnClanChangedKingdom));
				CampaignEvents.MapEventEnded.AddNonSerializedListener(this, new Action<MapEvent>(this.OnMapEventEnded));
				CampaignEvents.MapEventStarted.AddNonSerializedListener(this, new Action<MapEvent, PartyBase, PartyBase>(this.OnMapEventStarted));
				CampaignEvents.MobilePartyDestroyed.AddNonSerializedListener(this, new Action<MobileParty, PartyBase>(this.OnMobilePartyDestroyed));
				CampaignEvents.VillageBeingRaided.AddNonSerializedListener(this, new Action<Village>(this.OnVillageRaided));
				CampaignEvents.GameMenuOpened.AddNonSerializedListener(this, new Action<MenuCallbackArgs>(this.OnGameMenuOpened));
				CampaignEvents.HeroKilledEvent.AddNonSerializedListener(this, new Action<Hero, Hero, KillCharacterAction.KillCharacterActionDetail, bool>(this.OnHeroKilled));
			}

			// Token: 0x06004E64 RID: 20068 RVA: 0x00166CD5 File Offset: 0x00164ED5
			public override void OnHeroCanHaveQuestOrIssueInfoIsRequested(Hero hero, ref bool result)
			{
				if (hero == this._headmanNotable)
				{
					result = false;
				}
			}

			// Token: 0x06004E65 RID: 20069 RVA: 0x00166CE4 File Offset: 0x00164EE4
			private void OnHeroKilled(Hero victim, Hero killer, KillCharacterAction.KillCharacterActionDetail detail, bool showNotification = true)
			{
				if (victim == this._headmanNotable)
				{
					TextObject textObject = (detail == KillCharacterAction.KillCharacterActionDetail.Lost) ? this.TargetHeroDisappearedLogText : this.TargetHeroDiedLogText;
					StringHelpers.SetCharacterProperties("QUEST_TARGET", this._headmanNotable.CharacterObject, textObject, false);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					base.AddLog(textObject, false);
					base.CompleteQuestWithCancel(null);
				}
			}

			// Token: 0x06004E66 RID: 20070 RVA: 0x00166D50 File Offset: 0x00164F50
			private void OnGameMenuOpened(MenuCallbackArgs args)
			{
				if (args.MenuContext.GameMenu.StringId == "join_encounter" && this._battleStarted && PlayerEncounter.EncounteredBattle != null && PlayerEncounter.EncounteredBattle.InvolvedParties.Contains(this._rivalMobileParty.Party))
				{
					this._rivalMobileParty.MapEvent.IsInvulnerable = false;
				}
			}

			// Token: 0x04001A17 RID: 6679
			private const int PastureRadius = 8;

			// Token: 0x04001A18 RID: 6680
			private const int BattleFakeSimulationDuration = 5;

			// Token: 0x04001A19 RID: 6681
			[SaveableField(11)]
			private MobileParty _rivalMobileParty;

			// Token: 0x04001A1A RID: 6682
			[SaveableField(30)]
			private readonly Settlement _targetSettlement;

			// Token: 0x04001A1B RID: 6683
			[SaveableField(21)]
			private MobileParty _herdersMobileParty;

			// Token: 0x04001A1C RID: 6684
			[SaveableField(31)]
			private float _issueDifficultyMultiplier;

			// Token: 0x04001A1D RID: 6685
			[SaveableField(50)]
			private readonly Hero _headmanNotable;

			// Token: 0x04001A1E RID: 6686
			[SaveableField(80)]
			private string _questId;

			// Token: 0x04001A1F RID: 6687
			[SaveableField(90)]
			private int _rewardGold;

			// Token: 0x04001A20 RID: 6688
			[SaveableField(100)]
			private int _rivalPartySpawnDeltaTime;

			// Token: 0x04001A21 RID: 6689
			[SaveableField(110)]
			private bool _battleStarted;

			// Token: 0x04001A22 RID: 6690
			[SaveableField(120)]
			private int _spawnRivalPartyAfterHours;
		}

		// Token: 0x0200063B RID: 1595
		public class LandlordNeedsAccessToVillageCommonsIssueTypeDefiner : SaveableTypeDefiner
		{
			// Token: 0x06004E6A RID: 20074 RVA: 0x00166E05 File Offset: 0x00165005
			public LandlordNeedsAccessToVillageCommonsIssueTypeDefiner() : base(420000)
			{
			}

			// Token: 0x06004E6B RID: 20075 RVA: 0x00166E12 File Offset: 0x00165012
			protected override void DefineClassTypes()
			{
				base.AddClassDefinition(typeof(LandlordNeedsAccessToVillageCommonsIssueBehavior.LandlordNeedsAccessToVillageCommonsIssue), 1, null);
				base.AddClassDefinition(typeof(LandlordNeedsAccessToVillageCommonsIssueBehavior.LandlordNeedsAccessToVillageCommonsIssueQuest), 2, null);
			}
		}
	}
}
